package com.ht.api.call.func.impl.fan;

import com.ht.api.bean.AjaxResult;
import com.ht.api.bean.LoginBean;
import com.ht.api.call.ICall;
import com.ht.api.call.func.IFunctionCall;
import com.ht.api.db.Db;
import com.ht.api.db.Entity;
import com.ht.api.db.util.HtUtil;

import cn.hutool.json.JSONObject;

/**
 * 渠道广告位的新增前置函数
 */
public class PositionChannelAddBeforeFunctionCall implements IFunctionCall{

	@Override
	public String getName() {
		return "渠道广告位的新增前置函数";
	}

	@Override
	public JSONObject execute(LoginBean me, JSONObject param, AjaxResult result) {
		param.set("state", "position" + HtUtil.getId());
		param.set("status", -1);
		param.set("init_status", 0);

		Entity fanChannel = Entity.create("fan_channel");
		fanChannel.setMainId(param.getStr("channel_id"));
		fanChannel.set("position_cnt", 1);
		Db.insert(me.getDataSource(), fanChannel);

		Entity fanTeam = Entity.create("fan_team");
		fanTeam.setMainId(param.get("team_id"));
		fanTeam.set("relation_cnt", 1);
		Db.insert(me.getDataSource(), fanTeam);

		return null;
	}

}
